<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: GetCircle.php
 * Date: 2017/1/2
 * Time: 23:13
 */

namespace app\api\model\page\chat;

use app\api\model\dao\UserAccount;
use app\library\Common;
use app\library\Error;
use app\library\HuanXin;
use app\library\PageBase;

class BlackList extends PageBase
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * page 入口
     *
     * @param $param
     * @return array
     */
    public function excute($param)
    {
        $this->checkToken($param);

        $this->phone = !empty($this->phone) ? $this->phone : '';

        $this->data['list'] = [];

        $this->huanxin_username = Common::encryptString($this->phone);

        $ret = HuanXin::getBlacklist($this->huanxin_username);
        if (false === $ret) {
            return $this->getRes(Error::ERR_SYS);
        }

        $username = [];
        if (!empty($ret['data'])) {
            $username = $ret['data'];
        }

        if (empty($username)) {
            return $this->getRes();
        }
        $objAccount = new UserAccount();
        $user_account = $objAccount->getUserAccountByHuanxinUsernames($username);

        $data = [];
        foreach ($user_account as $val) {
            $data[] = [
                'userid' => $val['id'],
                'huanxin_userid' => $val['huanxin_username'],
                'name' => $val['nick_name'],
                'sex' => $val['sex'] ? 'F' : 'M',
                'photo' => $val['avatar']
            ];
        }

        $this->data['list'] = $data;

        return $this->getRes();

    }
}
